<template>
	<div>
	</div>
</template>

<script>
	const {
		dialog,
		app
	} = require('@electron/remote')
	import {
		name as pkgName
	} from "../../../../package.json";
	const path = require('path');
	const appDataPath = app.getPath('appData')
	const appFilePath = path.join(appDataPath, `/${pkgName}`)
	const fs = require('fs');
	
	export default {
		name: "Template",
		data() {
			return {
				exportPath: '',
			};
		},
		created() {
		},
		mounted() {
			this.getUserDataPath()
		},
		methods: {
			getUserDataPath() {
				// 存放文件路径
				this.exportPath = appFilePath + '/taskFile'
			
			},
			// 本地文件上传
			importLocalFile() {
				// 弹出文件选择框
				dialog.showOpenDialog({
					properties: ['openFile']
				}).then(result => {
					console.log(result);
					const sourcePath = result.filePaths[0]; // 获取选中的文件路径
					const fileName = path.basename(sourcePath); // 获取文件名
					//  需要保存给对象的 相对路径
					this.exportPath = path.join(this.exportPath, "/1111/");
					if (!fs.existsSync(this.exportPath)) {
						fs.mkdirSync(this.exportPath, {
							recursive: true
						});
					}
					const targetFilePath = path.join(this.exportPath, fileName); // 目标文件路径
					// 写入文件到固定路径
					fs.copyFileSync(sourcePath, targetFilePath);
			
					console.log('文件已保存至:', targetFilePath)
			
					console.log('文件已保存至:', targetFilePath)
			
					// }).catch(err => {
					// 	console.log(err);
					// });
				})
			}
		}
	};
</script>
<style scoped lang="scss">
</style>